import java.util.HashSet;
import java.util.Set;

public class Leetcode73 {

    public static void main(String[] args) {
    }

    public void setZeroes(int[][] matrix) {
        int m = matrix.length;
        int n = matrix[0].length;
        Set<Integer> needCleanRowIndex = new HashSet<>();
        Set<Integer> needCleanColumnIndex = new HashSet<>();
        for (int rowIndex = 0; rowIndex < m; rowIndex++) {
            for (int columnIndex = 0; columnIndex < n; columnIndex++) {
                if (matrix[rowIndex][columnIndex] == 0) {
                    needCleanColumnIndex.add(columnIndex);
                    needCleanRowIndex.add(rowIndex);
                }
            }
        }

        for (Integer columnIndex : needCleanColumnIndex) {
            for (int rowIndex = 0; rowIndex < m; rowIndex++) {
                matrix[rowIndex][columnIndex] = 0;
            }
        }

        for (Integer rowIndex : needCleanRowIndex) {
            for (int columnIndex = 0; columnIndex < n; columnIndex++) {
                matrix[rowIndex][columnIndex] = 0;
            }
        }
    }

}
